var util = require("../../../utils/util.js"),
    {
        api
    } = require("../../../utils/api.js"),
    app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        order_no: "",
        qrcode:'',
        goods_type: '1',
        loading: false,
        message: '',
        totalMoney: 0,
        userInfo: null,
        bangsHeight: wx.getStorageSync('navBarObj').bangsHeight-40,
        orderDetail: {},
        couponDetail:{}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        wx.hideShareMenu()
        this.setData({
            order_no: options.order_no,
            goods_type: options.goods_type || '1'
        })
        if(this.data.goods_type == 2){
            this.couponQrcode();
            this.couponQrcodeDetail();
        }else{
            this.getHxQrcode();
            this.getOrderDetail();
        }
        
        
    },
    async getOrderDetail() {
        const {
            data
        } = await api.getOrderDetail(this.data.order_no);
        this.setData({
            orderDetail: data && data.detail ? data.detail : {},
            orderGoodsList: data && data.detail && Array.isArray(data.detail.ordergoods) ? data.detail.ordergoods : []
        })
    },
    async couponQrcodeDetail(){
        const {
            data
        } = await api.couponQrcodeDetail(this.data.order_no);
        this.setData({
            couponDetail: data && data.coupon ? data.coupon : {}
        })
    },
    async getHxQrcode() {
        const data = await api.getHxQrcode(this.data.order_no);
        if(data && data.data)this.setData({qrcode:data.data.qrcode})
    },
    async couponQrcode() {
        const data = await api.couponQrcode(this.data.order_no);
        if(data && data.data)this.setData({qrcode:data.data.qrcode})
    },
    onChange(e) {
        this.setData({
            playType: e.detail
        })
    },
    onChangeMsg(e) {
        this.setData({
            message: e.detail
        })
    },
    goback() {
        wx.navigateBack();
    },
    gotoGoodsDetail(e) {
        let id = e.currentTarget.dataset.id;
        let type = this.data.goods_type == 1?(this.data.orderDetail.type == 0?1:2):2;
        wx.navigateTo({
            url: `/pages/shopping/goodsDetail/goodsDetail?id=${id}&type=${type}`
        })
    },
    //点击一键复制
    copyBtn: function (e) {
        var that = this;
        wx.setClipboardData({
            //准备复制的数据内容
            data: that.data.orderDetail.order_no,
            success: function (res) {
                wx.showToast({
                    title: '复制成功',
                });
            }
        });
    },
    goKf(){
        let phone=this.data.goods_type == 2?this.data.couponDetail.store.contact_phone:this.data.orderDetail.store.contact_phone;
        app.getKf(phone)
      },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage(e) {

    }
})